<?php
require_once 'Zend/Auth.php';
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) {

$user=$auth->getIdentity()->id;
if($user != 1):
header ("Location: /adm/login.php");
endif;
}else
{
    header("Location: /adm/login.php");
    
}
require('../class/sql.php');
require('../class/sitemap.php');
if(isset($_POST['id'])&&($_POST['id'] == 'news'))
{
    //new post
    /*
    [title_post] => Главная
    [url_post] => /net
    [category] => 1
    [meta_key] => Главная, кей
    [meta_desc] => Главная деск
    [content] =>
     `id`, `cat_id`, `url`, `title`, `content`, `meta_key`, `meta_desc`, `index_page`
    */
    if(isset($_POST['index_page'])){$index= 1;}else{$index=0;}
    $dates=date('Y:m:d G:i:s');
    $data = array('cat_id' =>$_POST['category'],'url'=>$_POST['url_post'],
                                    'title'=>$_POST['title_post'],
                                    'content'=>$_POST['content'],
                                    'meta_key'=>$_POST['meta_key'],
                                    'meta_desc'=>$_POST['meta_desc'],
                                    'index_page'=>$index,
                                    'date_post'=>$dates);
    $addpost = $db->insert('content',$data);
    sitemap();
    
}elseif(isset($_POST['id'])&&($_POST['id'] != 'news'))
{
    //update post
    if(isset($_POST['index_page'])){$index= 1;}else{$index=0;}
    $data = array('cat_id' =>$_POST['category'],'url'=>$_POST['url_post'],
                                    'title'=>$_POST['title_post'],
                                    'content'=>$_POST['content'],
                                    'meta_key'=>$_POST['meta_key'],
                                    'meta_desc'=>$_POST['meta_desc'],
                                    'index_page'=>$index);
    $where = $db->quoteInto('id = ?',$_POST['id']);
    $updatepost = $db->update('content',$data,$where);
}

//sleep(10);
$url = "http://".$_SERVER['HTTP_HOST']."/adm/edit.php";
header("Location: $url");
?>